#include"Processbar.h"
#include<string.h>
#include<unistd.h>
//void Fortest()
//{
//     printf("this is for test\n");
//     printf("this is for test\n");
//    printf("this is for test\n");
//     printf("this is for test\n");
//}	
#define Length 110
#define Style '#'

const char*lable="|/-\\";

//version1:
//void ProcBar()
//
//    char bar[Length];
//    memset(bar,'\0',sizeof(bar));
//    int cnt=0;
//    int len=strlen(lable);
//    while(cnt<=100)
//    {
//        printf("[%-100s][%3d%%][%c]\r",bar,cnt,lable[cnt%len]);
//        fflush(stdout);
//       bar[cnt++]=Style;
//       usleep(10000);
//    }
//    printf("\n");
//

//version2
void ProcBar(double total,double current)
{
    char bar[Length];
    memset(bar,'\0',sizeof(bar));
    int cnt=0;
    double rate=(current*100.0)/total;
    int loop_count=(int)rate;
    int len=strlen(lable);
    while(cnt<=loop_count)
    {
        printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
        fflush(stdout);
       bar[cnt++]=Style;
      // usleep(10000);
    }
   // printf("\n");

}

